package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Permission;
import cn.wolfcode.domain.Role;
import cn.wolfcode.qo.JsonResult;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IPermissionService;
import cn.wolfcode.service.IRoleService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @RequiredPermission(name = "权限页面" , expression = "permission:list")
    @RequestMapping("/list")
    public String list(QueryObject qo, Model model) {
        PageInfo<Permission> pageInfo = permissionService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "permission/list";
    }
    @ResponseBody
    @RequestMapping("/reload")
    public JsonResult reload(){
        JsonResult jsonResult = new JsonResult();
        try {
            permissionService.reload();
            jsonResult.setSuccess(true);
            jsonResult.setMsg("加载成功");
        } catch (Exception e) {
            jsonResult.setSuccess(false);
            jsonResult.setMsg("加载失败");
            e.printStackTrace();
        }
        return jsonResult;
    }

}
